package com.fsnbigdata.service.impl;
import com.fsnbigdata.service.api.TaxonomyService;
import org.springframework.roo.addon.layers.service.annotations.RooServiceImpl;
import com.fsnbigdata.domain.Organism;
import com.fsnbigdata.domain.Taxonomy;
import com.fsnbigdata.repository.TaxonomyRepository;
import io.springlets.data.domain.GlobalSearch;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * = TaxonomyServiceImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooServiceImpl(service = TaxonomyService.class)
@Service
@Transactional(readOnly = true)
public class TaxonomyServiceImpl implements TaxonomyService {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    private TaxonomyRepository taxonomyRepository;

    /**
     * TODO Auto-generated constructor documentation
     *
     * @param taxonomyRepository
     */
    @Autowired
    public TaxonomyServiceImpl(TaxonomyRepository taxonomyRepository) {
        setTaxonomyRepository(taxonomyRepository);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return TaxonomyRepository
     */
    public TaxonomyRepository getTaxonomyRepository() {
        return taxonomyRepository;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param taxonomyRepository
     */
    public void setTaxonomyRepository(TaxonomyRepository taxonomyRepository) {
        this.taxonomyRepository = taxonomyRepository;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param entity
     * @return Taxonomy
     */
    @Override
    @Transactional
    public Taxonomy save(Taxonomy entity) {
        return getTaxonomyRepository().save(entity);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     * @return Taxonomy
     */
    @Override
    public Taxonomy findOne(Long id) {
        return getTaxonomyRepository().findOne(id);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     * @return Taxonomy
     */
    @Override
    public Taxonomy findOneForUpdate(Long id) {
        return getTaxonomyRepository().findOneDetached(id);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param ids
     * @return List
     */
    @Override
    public List<Taxonomy> findAll(Iterable<Long> ids) {
        return getTaxonomyRepository().findAll(ids);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organism
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    @Override
    public Page<Taxonomy> findByOrganism(Organism organism, GlobalSearch globalSearch, Pageable pageable) {
        return getTaxonomyRepository().findByOrganism(organism, globalSearch, pageable);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organism
     * @return Long
     */
    @Override
    public long countByOrganism(Organism organism) {
        return getTaxonomyRepository().countByOrganism(organism);
    }
    
    @Override
    public Long findByFamilyAndGenus(String family, String genus) {
        return getTaxonomyRepository().findIdByFamilyAndGenus(family,genus);
    }
    
    @Override
    public Taxonomy findByOrganismId(long organism_id) {
        return getTaxonomyRepository().findByOrganismId(organism_id);
    }

    @Override
    public List<Object> queryByOrganismId(List<Long> s) {
        return taxonomyRepository.queryByOrganismId(s);
    }

    @Override
    public Taxonomy getByOrganismId(long id) {
        return taxonomyRepository.findOne( id );
    }

    @Override
    public List<Object> queryByFamily(Object l,List<Long> ids) {
        return taxonomyRepository.queryGenusById( l,ids );
    }


    /**
     * TODO Auto-generated method documentation
     *
     * @return Class
     */
    @Override
    public Class<Taxonomy> getEntityType() {
        return Taxonomy.class;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Class
     */
    @Override
    public Class<Long> getIdType() {
        return Long.class;
    }
}
